package study.web.service.cxf.soap11.client;

import java.util.ArrayList;
import java.util.List;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import study.web.service.cxf.pojo.WeatherModel;
import study.web.service.cxf.soap11.impl.Weather;
import study.web.service.cxf.soap11.impl.WeatherInterface;

/**  
* @Name: WeatherClient
* @Description: 天气信息查询客户端02（使用JaxwsProxyFactoryBean代理类实现）
* @Author: 李超
* @version 1.0
* @Create Date: 2017-01-07
*/
public class WeatherClient02 {
	
	public static void main(String[] args) {
		//1、创建代理工厂bean
		JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean() ;
		//2、设置接口类型(portType)
		jaxWsProxyFactoryBean.setServiceClass(WeatherInterface.class) ;
		//3、设置webservice地址
		jaxWsProxyFactoryBean.setAddress("http://127.0.0.1:12345/weather");
		//4、创建portType实例对象
		WeatherInterface weatherInterface =(WeatherInterface) jaxWsProxyFactoryBean.create();
		//5、调用服务
		List<Weather> weatherList = weatherInterface.queryWeatherByCityName("郑州");
		//6、将响应数据转换为客户端对象集合
		List<WeatherModel> list = null ;
		if(weatherList != null && weatherList.size() > 0) {
			list = new ArrayList<>() ;
			for (Weather weather : weatherList) {
				WeatherModel weatherModel = new WeatherModel() ;
				weatherModel.setDetail(weather.getDetail()) ;
				weatherModel.setDate(weather.getDate().toGregorianCalendar().getTime()) ;
				weatherModel.setTemperature_max(weather.getTemperatureMax()) ;
				weatherModel.setTemperature_min(weather.getTemperatureMin()) ;
				list.add(weatherModel) ;
			}
		}
		for (WeatherModel weatherModel : list) {
			System.out.println(weatherModel);
		}
	}

}
